package com.xunshibao.core.utils;

import java.io.StringWriter;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.ObjectMapper;

public abstract class JsonUtil {
	private static final ObjectMapper mapper = new ObjectMapper();

	public static String toJson(Object obj) {
		StringWriter out = new StringWriter();
		try {
			JsonGenerator generator = mapper.getJsonFactory().createJsonGenerator(out);
			mapper.writeValue(generator, obj);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return out.toString();
	}
}
